package com.hyst.web;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hyst.common.ResultBean;
import com.hyst.common.ResultPage;
import com.hyst.domain.WechatInterfaceView;
import com.hyst.service.WechatInterfaceViewService;

/**
 * @Description:controller
 * @author：dy 
 *@Date：2018年09月23日
 */
@RestController
@RequestMapping("wechatInterfaceViews")
@CrossOrigin(maxAge = 3600, origins = "*")
public class WechatInterfaceViewController {
	@Autowired
	private WechatInterfaceViewService wechatInterfaceViewService;
	// 2018-9-24 chenbin: 
	private static ObjectMapper objectMapper=new ObjectMapper();
	
	@GetMapping
	public ResultPage<WechatInterfaceView> list(WechatInterfaceView wechatInterfaceView) {
		return ResultPage.success(wechatInterfaceViewService.list(wechatInterfaceView));
	}

	@PostMapping
	public ResultBean<WechatInterfaceView> creat(final WechatInterfaceView wechatInterfaceView) {
		return ResultBean.success(wechatInterfaceViewService.insert(wechatInterfaceView));
	}

	/**
	 * @Description: 根据主键查询
	 * @param studentId
	 * @return ResultBean<WechatInterfaceView>
	 */
	@GetMapping("{studentId}")
	public ResultBean<WechatInterfaceView> getByPriKey(@PathVariable("studentId") final String studentId) {
		return ResultBean.success(wechatInterfaceViewService.getByPriKey(studentId));
	}

	/**
	 * @Description: 根据主键更新全字段
	 * @param wechatInterfaceView
	 * @return ResultBean<WechatInterfaceView>
	 */
	@PatchMapping("{studentId}")
	public ResultBean<WechatInterfaceView> update(final WechatInterfaceView wechatInterfaceView) {
		return ResultBean.success(wechatInterfaceViewService.update(wechatInterfaceView));
	}

	/**
	 * @Description: 根据主键更新不为默认值的字段
	 * @param wechatInterfaceView
	 * @return ResultBean<WechatInterfaceView>
	 */
	//@PutMapping("{studentId}")
	@PostMapping("{studentId}")
	public ResultBean<WechatInterfaceView> updatePatch(@PathVariable("studentId") final String studentId,
			final WechatInterfaceView wechatInterfaceView) {
		return ResultBean.success(wechatInterfaceViewService.updateSelective(wechatInterfaceView));
	}

	/**
	 * @Description: 根据主键删除
	 * @param studentId
	 * @return ResultBean<WechatInterfaceView>
	 */
	@DeleteMapping("{studentId}")
	public ResultBean<WechatInterfaceView> delete(@PathVariable("studentId") final String studentId) {
		return ResultBean.success(wechatInterfaceViewService.delete(studentId));
	}
	
	// chenbin: 微信接口，根据手机号查询课程信息
	/**
	 * @Description: 根据主键查询
	 * @param studentId
	 * @return ResultBean<WechatInterfaceView>
	 */
	
	@GetMapping("getByPhone/{phone}")
	public ResultBean<Map<String, String>> getByPhone(@PathVariable("phone") final String phone) {
//		return ResultBean.success(wechatInterfaceViewService.getByPhone(phone));
		return ResultBean.success(wechatInterfaceViewService.getMap(phone));
	}


}
